/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.d2g.realestate.facade;

import br.com.d2g.realestate.persistence.Owner;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author d2g
 */
@Stateless
public class OwnerFacade extends AbstractFacade<Owner> {
    @PersistenceContext(unitName = "WebApplication2PU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public OwnerFacade() {
        super(Owner.class);
    }
    
    public List<Owner> searchOwnerByUsername(String username, int[] range) {
        TypedQuery searchOwnerByUsernameQuery = this.em.createNamedQuery("Owner.findByUsername", Owner.class);
        searchOwnerByUsernameQuery.setParameter("username", username);
        searchOwnerByUsernameQuery.setMaxResults(range[1] - range[0]);
        searchOwnerByUsernameQuery.setFirstResult(range[0]);
        return searchOwnerByUsernameQuery.getResultList();
    }

    public int countSearchOwnerByUsername(String username) {
        return 1;
    }
    
}
